<template>
    <div class="userForm">
        <div class="contentMid"></div>
        <el-card class="box-card">
            <el-row :gutter="10">
                <el-col :span="8">
                    取证名称：
                    <el-input class="phoneIput" v-model="input" placeholder="请输入取证名称" />
                </el-col>
                <el-col :span="8">
                    取证编号：
                    <el-input class="phoneIput" v-model="input2" placeholder="请输入取证编号" />
                </el-col>
                <el-col :span="8">
                    取证名称：
                    <el-input class="phoneIput" v-model="input3" placeholder="请输入文件名称" />
                </el-col>
            </el-row>
            <el-row :gutter="10">
                <el-col :span="16">
                    取证时间：
                    <el-config-provider :locale="zhCn">
                        <el-date-picker style="width: 226px; height: 38px" v-model="regTime" type="daterange"
                            start-placeholder="开始日期" end-placeholder="结束日期" />
                    </el-config-provider>
                </el-col>
                <el-col :span="8">
                    <div class="flotBt">
                        <el-button type="primary" @click="insert">查询</el-button>
                        <el-button @click="choat">重置</el-button>
                    </div>
                </el-col>
            </el-row>
            <div class="userTable">
                <el-button type="primary" :icon="Plus" style="margin-bottom: 15px;" @click="obtainAdd()">新增取证</el-button>
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column prop="obtainum" label="取证编号" />
                    <el-table-column prop="name" label="取证名称" />
                    <el-table-column prop="obtabag" label="证据大小" />
                    <el-table-column prop="obtdiz" label="取证地址" />
                    <el-table-column label="取证时间">
                        <template #default="slot">
                            {{ new Date(slot.row.obtdate).toLocaleString() }}
                        </template>
                    </el-table-column>
                    <el-table-column label="取证状态">
                        <template #default="slot">
                            <span v-if="slot.row.obtate == '1'">
                                <el-icon color="#0079fe">
                                    <WarningFilled />
                                </el-icon>上链中</span>
                            <span v-if="slot.row.obtate == '2'"><el-icon color="#4bd863">
                                    <CircleCheckFilled />
                                </el-icon>成功</span>
                            <span v-if="slot.row.obtate == '3'"><el-icon color="#ff3b31">
                                    <CircleCloseFilled />
                                </el-icon>失败</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="address" label="操作">
                        <template #default="scope">
                            <el-button link type="primary" size="small" @click="jumpPage">
                                <svg-icon style="margin-right: 3px" iconName="icon-view"></svg-icon>
                                详情
                            </el-button>
                            <el-button link type="primary" size="small" @click="dialogVisible = true">
                                <svg-icon style="margin-right: 3px" iconName="icon-tongguo"></svg-icon>
                                下载证书
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="userPage">
                <el-config-provider :locale="zhCn">
                    <el-pagination background v-model:current-page="currentPage4" v-model:page-size="pageSize4"
                        :page-sizes="[2, 4, 6, 8]" :small="small" layout="total, sizes, prev, pager, next, jumper"
                        :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
                </el-config-provider>

            </div>
        </el-card>
        <div class="contentMid"></div>
        <!-- 审核弹框 -->
        <el-dialog align-center id="dialog" v-model="dialogVisible" title="认证审核" width="30%" :before-close="handleClose">
            <el-form ref="formRef" :model="dynamicValidateForm" label-width="90px" class="demo-dynamic">
                <el-form-item prop="email" label="认证审核" :rules="[
                        {
                            required: true,
                            message: 'Please input email address',
                            trigger: 'blur',
                        },
                    ]">
                    <el-select style="width: 280px" v-model="dynamicValidateForm.email" placeholder="审核通过" size="large">
                        <el-option v-for="item in tipPass" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item v-for="(domain, index) in dynamicValidateForm.domains" :key="domain.key" label="审核备注">
                    <el-input style="width: 280px" v-model="domain.value" placeholder="请输入审核备注" />
                </el-form-item>
                <el-divider />
                <el-form-item>
                    <div style="position: relative; left: 200px">
                        <el-button @click="dialogVisible = false">取消</el-button>
                        <el-button style="background-color: #1abc9c; color: #fff" @click="dialogVisible = false">
                            确定
                        </el-button>
                    </div>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
  
<script setup lang="ts">
import { ref } from "vue";
import { ElMessageBox } from "element-plus";
import { reactive, onMounted } from "vue";
import type { FormInstance } from "element-plus";
import { useRouter } from "vue-router";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { Plus } from '@element-plus/icons-vue'
import axios from "axios";
const router = useRouter();
// 搜索
const input = ref("");
const input2=ref("");
const input3=ref("")
const select = ref(""); // 实名认证
const status = ref("");
const regTime = ref("");
const reqTime = ref("");
const choat=()=>{
    input.value=""
    input2.value=""
    input3.value=""
}
// 分页
const currentPage4 = ref(1);
const pageSize4 = ref(2);
const small = ref(false);
// 弹框
const dialogVisible = ref(false);
const tipPass = [
    {
        value: "审核通过",
        label: "审核通过",
    },
    {
        value: "审核不通过",
        label: "审核不通过",
    },
];
const tableData = ref([])
let total = ref(0);
const obtainAdd = () => {
    router.push("/console/obtainadd")
}
const insert = async () => {
    let { data } = await axios.get("/api/opertion/obtlist", { params: { page: currentPage4.value, pagesize: pageSize4.value,input:input.value,value:regTime.value} });
    tableData.value = data.data;
    total.value = data.total
}
onMounted(() => {
    insert()
})
// 跳转到用户详情页面
const jumpPage = () => {
    router.push("/console/obtaininfo");
};
const handleSizeChange = (val: number) => {
    pageSize4.value = val;
    insert()
};
const handleCurrentChange = (val: number) => {
    currentPage4.value = val;
    insert()
};
const handleClose = (done: () => void) => {
    ElMessageBox.confirm("Are you sure to close this dialog?")
        .then(() => {
            done();
        })
        .catch(() => {
            // catch error
        });
};
const formRef = ref<FormInstance>();
const dynamicValidateForm = reactive<{
    domains: DomainItem[];
    email: string;
}>({
    domains: [
        {
            key: 1,
            value: "",
        },
    ],
    email: "",
});

interface DomainItem {
    key: number;
    value: string;
}
</script>
  
<style scoped>
.userForm {
    background-color: #fbfbfb;
    height: 90%;
}

.contentMid {
    height: 30px;
}

.phoneIput {
    width: 240px;
    height: 38px;
}

.m-2 {
    width: 240px;
}

.flotBt {
    text-align: center;
    position: relative;
    left: 65px;
}

.userTable {
    margin-top: 46px;
}

.userPage {
    margin-top: 30px;
    float: right;
}

#dialog .el-dialog__header {
    padding: var(--el-dialog-padding-primary);
    padding-bottom: 10px;
    margin-right: 16px;
    background: #f2f2f2 !important;
}

.dialog-but {
    float: left;
}

.el-row {
    margin-bottom: 20px;
}

.el-row:last-child {
    margin-bottom: 0;
}

.dialog-footer button:first-child {
    margin-right: 10px;
}

.el-col {
    border-radius: 4px;
}

.grid-content {
    border-radius: 4px;
    min-height: 38px;
}

.demo-pagination-block+.demo-pagination-block {
    margin-top: 10px;
}

.demo-pagination-block .demonstration {
    margin-bottom: 16px;
}

/* 卡片 */

.box-card {
    padding: 20px 40px;
    width: 89%;
    margin: auto;
    min-height: 530px;
}
</style>